home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / heap55.com / HPAT55.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1990-01-07  |  5.6 KB  |  151 lines

  1. {*****************************************************************************
  2.  This program patches TPC.EXE, version 5.5. The resulting command line
  3.  compiler can produce additional code to call a user-supplied routine whenever
  4.  a pointer is dereferenced. The user-supplied routine can perform any of a
  5.  variety of operations: error-checking the pointer, transparently supporting
  6.  handle-based pointers for heap compaction, or implementing a complete virtual
  7.  heap in EMS or on disk.
  8.  
  9.  To use this program, compile it and run it from a directory where a copy of
  10.  TPC.EXE resides. The program directly changes TPC.EXE -- no backup is made.
  11.  The program works only on version 5.50 of Turbo Pascal, which to our
  12.  knowledge is the only released version of Turbo 5.5. We have not developed a
  13.  similar patch for TURBO.EXE -- that would be possible, but the integrated
  14.  compiler is linked differently, making it a chore to find the patch
  15.  locations.
  16.  
  17.  If the patching program halts with an error, be sure to restore a fresh copy
  18.  of TPC.EXE from a backup. At the time of the error, the compiler may be
  19.  partially patched.
  20.  
  21.  For further information on using the patched compiler, refer to HEAP.DOC.
  22.  
  23.  Written 1/6/90, Kim Kokkonen, TurboPower Software.
  24.    Thanks to Chris Franzen of O.K.Soft, West Germany, for tracking down the
  25.    locations in the version 5.5 compiler that corresponded to the ones I
  26.    found in earlier versions.
  27. *****************************************************************************}
  28.  
  29. {$R-,S-,I+,F-,B-,V-}
  30.  
  31. program HeapPatch;
  32. const
  33.   DerefInterrupt = $66; {Change this constant to use a different
  34.                          interrupt number to call the user routine}
  35. type
  36.   PatchRec =            {Describes one patch}
  37.     record
  38.       P : LongInt;      {File position}
  39.       O : Byte;         {Original byte}
  40.       N : Byte;         {New byte}
  41.     end;
  42.  
  43. const
  44.   PatchFileSize = 61926;
  45.   NumPatches = 70;
  46.   PatchArray : array[1..NumPatches] of PatchRec = (
  47.     (P : $000008AE; O : $0B; N : $46),         {Adjust start of patch area}
  48.     (P : $000008B3; O : $80; N : $63),         {Adjust length of patch area}
  49.     (P : $0000090B; O : $90; N : $F7),         {Interrupt generation code}
  50.     (P : $0000090C; O : $90; N : $06),
  51.     (P : $0000090D; O : $90; N : $0A),
  52.     (P : $0000090E; O : $90; N : $2A),
  53.     (P : $0000090F; O : $90; N : $08),
  54.     (P : $00000910; O : $90; N : $00),
  55.     (P : $00000911; O : $90; N : $74),
  56.     (P : $00000912; O : $90; N : $06),
  57.     (P : $00000913; O : $90; N : $B8),
  58.     (P : $00000914; O : $90; N : $CD),
  59.     (P : $00000915; O : $90; N : DerefInterrupt),
  60.     (P : $00000916; O : $90; N : $E8),
  61.     (P : $00000917; O : $90; N : $EC),
  62.     (P : $00000918; O : $90; N : $75),
  63.     (P : $00000919; O : $90; N : $E9),
  64.     (P : $0000091A; O : $90; N : $9F),
  65.     (P : $0000091B; O : $90; N : $75),
  66.     (P : $0000091C; O : $90; N : $00),         {Expanded option mask table}
  67.     (P : $0000091E; O : $90; N : $40),
  68.     (P : $0000091F; O : $90; N : $00),
  69.     (P : $00000920; O : $90; N : $00),
  70.     (P : $00000921; O : $90; N : $81),
  71.     (P : $00000922; O : $90; N : $00),
  72.     (P : $00000923; O : $90; N : $00),
  73.     (P : $00000924; O : $90; N : $00),
  74.     (P : $00000925; O : $90; N : $84),
  75.     (P : $00000926; O : $90; N : $00),
  76.     (P : $00000927; O : $90; N : $00),
  77.     (P : $00000928; O : $90; N : $00),
  78.     (P : $00000929; O : $90; N : $00),
  79.     (P : $0000092A; O : $90; N : $20),
  80.     (P : $0000092B; O : $90; N : $00),
  81.     (P : $0000092C; O : $90; N : $01),
  82.     (P : $0000092D; O : $90; N : $00),
  83.     (P : $0000092E; O : $90; N : $00),
  84.     (P : $0000092F; O : $90; N : $00),
  85.     (P : $00000930; O : $90; N : $00),
  86.     (P : $00000931; O : $90; N : $00),
  87.     (P : $00000932; O : $90; N : $00),
  88.     (P : $00000933; O : $90; N : $00),
  89.     (P : $00000934; O : $90; N : $00),
  90.     (P : $00000935; O : $90; N : $82),
  91.     (P : $00000936; O : $90; N : $00),
  92.     (P : $00000937; O : $90; N : $00),
  93.     (P : $00000938; O : $90; N : $80),
  94.     (P : $00000939; O : $90; N : $80),
  95.     (P : $0000093A; O : $90; N : $00),
  96.     (P : $0000093B; O : $90; N : $88),
  97.     (P : $0000093C; O : $90; N : $02),
  98.     (P : $0000093D; O : $90; N : $00),
  99.     (P : $0000093E; O : $90; N : $04),
  100.     (P : $0000093F; O : $90; N : $00),
  101.     (P : $00000940; O : $90; N : $00),
  102.     (P : $00000941; O : $90; N : $00),
  103.     (P : $00000942; O : $90; N : $10),
  104.     (P : $00000943; O : $90; N : $00),
  105.     (P : $00000944; O : $90; N : $08),
  106.     (P : $00000945; O : $90; N : $00),
  107.     (P : $00004A95; O : $24; N : $74),         {Activate pointer gen code}
  108.     (P : $00004A96; O : $34; N : $BE),
  109.     (P : $000098D9; O : $D2; N : $1C),         {Refer to new option table}
  110.     (P : $000098DA; O : $9A; N : $07),
  111.     (P : $000099CD; O : $D2; N : $1C),         {Refer to new option table}
  112.     (P : $000099CE; O : $9A; N : $07),
  113.     (P : $00009CD1; O : $00; N : $01),         {Add $P option}
  114.     (P : $00009CD2; O : $00; N : $50),
  115.     (P : $00009CD3; O : $90; N : $00),
  116.     (P : $0000DC88; O : $20; N : $70)          {Mark compiler as patched}
  117.    );
  118.  
  119. var
  120.   f : file of Byte;
  121.   i : word;
  122.   b : byte;
  123.  
  124.   procedure Abort;
  125.   begin
  126.     WriteLn('Cannot complete patch. Be sure to restore a clean copy of TPC.EXE');
  127.     Halt(1);
  128.   end;
  129.  
  130. begin
  131.   Assign(f, 'TPC.EXE');
  132.   Reset(f);
  133.   if FileSize(f) <> PatchFileSize then begin
  134.     WriteLn('Unknown version of TPC.EXE');
  135.     Abort;
  136.   end;
  137.  
  138.   for i := 1 to numpatches do
  139.     with patcharray[i] do begin
  140.       seek(f, P);
  141.       read(f, b);
  142.       if b <> O then
  143.         abort;
  144.       seek(f, P);
  145.       write(f, N);
  146.     end;
  147.  
  148.   Close(f);
  149.   WriteLn('TPC.EXE 5.5 patched for pointer-dereference interrupts');
  150. end.
  151.